package com.eleventwelve.iris.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.eleventwelve.iris.entity.MedicalProgramTreatment;
import com.eleventwelve.iris.service.MedicalProgramTreatmentService;

public class MedicalProgramTreatmentDetailsController extends AbstractController{
	private String viewName;
	private String preview;
	private MedicalProgramTreatmentService medicalProgramTreatmentService;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();

		MedicalProgramTreatment treatment = null;
		
		
		String programId = request.getParameter("id");
		if(!StringUtil.isEmpty(programId) && StringUtils.isNumeric(programId)){
			treatment = medicalProgramTreatmentService.load(programId);
		}
		
		if(treatment!=null){
			map.put("treatment", treatment);
			
			return new ModelAndView(viewName, map);
			
		} else {
			return new ModelAndView(viewName);	//should be error page
		}
	}

	public String getViewName() {
		return viewName;
	}

	public void setViewName(String viewName) {
		this.viewName = viewName;
	}

	public String getPreview() {
		return preview;
	}

	public void setPreview(String preview) {
		this.preview = preview;
	}

	public MedicalProgramTreatmentService getMedicalProgramTreatmentService() {
		return medicalProgramTreatmentService;
	}

	public void setMedicalProgramTreatmentService(
			MedicalProgramTreatmentService medicalProgramTreatmentService) {
		this.medicalProgramTreatmentService = medicalProgramTreatmentService;
	}

}
